package com.bawei.yangzongcai___day2.MVPActivity;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * create by ertu
 * create on 2021/7/26
 * description
 */
public class Okhttpcilite  {

    public static Okhttpcilite okhttpcilite;

    //初始化本地协议
    public static Okhttpcilite getInstance() {
        //判断当前协议是否是空是空值就在创建一个新的协议
        if (okhttpcilite==null)
        {
            okhttpcilite = new Okhttpcilite();
        }
        return okhttpcilite;//如果当前协议不是空值就返回当前协议
    }

    //改造和拦截器
    public Retrofit  retrofit(String sma){
        return new Retrofit.Builder()
                //设置地址
                .baseUrl(sma)
                //设置网络协议请求拦截器
                .client(new OkHttpClient.Builder()
                        .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                        //建造完成
                        .build())
                //添加当前适配器的RxJava2的网络请求
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                //添加Gson解读
                .addConverterFactory(GsonConverterFactory.create())
                //建造完成
                .build();
    }

}
